//============================================================
// Producnt name:		Wz
// Version: 			1.0
// Coded by:			Wz (13066628480@163.com)
// Auto generated at: 	2016/10/27 18:00:50
//============================================================

using System;
using System.Collections.Generic;
using System.Text;
using Cloud.Model;
using System.Data.SqlClient;
using System.Data;
namespace Cloud.DAL
{
	public static class Sms_outboxService
	{
		#region SqlCommandText
		private const string Save_CommandText = "insert into Sms_outbox values(@sismsid,@extcode,@destaddr,@messagecontent,@reqdeliveryreport,@msgfmt,@sendmethod,@requesttime,@applicationid)";
		private const string Update_CommandText = "Update Sms_outbox set sismsid = @sismsid,extcode = @extcode,destaddr = @destaddr,messagecontent = @messagecontent,reqdeliveryreport = @reqdeliveryreport,msgfmt = @msgfmt,sendmethod = @sendmethod,requesttime = @requesttime,applicationid = @applicationid where id = @id";
		private const string Delete_CommandText = "delete from Sms_outbox where id = @id";
		private const string FindAll_CommandText = "select * from Sms_outbox";
		private const string FindById_CommandText = "select * from Sms_outbox where id=@id";
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region Save
		public static int Save(Sms_outbox sms_outbox)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@sismsid",SqlDbType.VarChar),
				new SqlParameter("@extcode",SqlDbType.VarChar),
				new SqlParameter("@destaddr",SqlDbType.VarChar),
				new SqlParameter("@messagecontent",SqlDbType.VarChar),
				new SqlParameter("@reqdeliveryreport",SqlDbType.Int),
				new SqlParameter("@msgfmt",SqlDbType.Int),
				new SqlParameter("@sendmethod",SqlDbType.Int),
				new SqlParameter("@requesttime",SqlDbType.DateTime),
				new SqlParameter("@applicationid",SqlDbType.VarChar)
				};
			pars[0].Value=sms_outbox.Sismsid;
			pars[1].Value=sms_outbox.Extcode;
			pars[2].Value=sms_outbox.Destaddr;
			pars[3].Value=sms_outbox.Messagecontent;
			pars[4].Value=sms_outbox.Reqdeliveryreport;
			pars[5].Value=sms_outbox.Msgfmt;
			pars[6].Value=sms_outbox.Sendmethod;
			pars[7].Value=sms_outbox.Requesttime;
			pars[8].Value=sms_outbox.Applicationid;
	
			return DBHelper.ExecuteNonQuery(Save_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Update
		public static int Update(Sms_outbox sms_outbox)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@id",SqlDbType.Int),
				new SqlParameter("@sismsid",SqlDbType.VarChar),
				new SqlParameter("@extcode",SqlDbType.VarChar),
				new SqlParameter("@destaddr",SqlDbType.VarChar),
				new SqlParameter("@messagecontent",SqlDbType.VarChar),
				new SqlParameter("@reqdeliveryreport",SqlDbType.Int),
				new SqlParameter("@msgfmt",SqlDbType.Int),
				new SqlParameter("@sendmethod",SqlDbType.Int),
				new SqlParameter("@requesttime",SqlDbType.DateTime),
				new SqlParameter("@applicationid",SqlDbType.VarChar)
				};
			pars[0].Value=sms_outbox.Id;
			pars[1].Value=sms_outbox.Sismsid;
			pars[2].Value=sms_outbox.Extcode;
			pars[3].Value=sms_outbox.Destaddr;
			pars[4].Value=sms_outbox.Messagecontent;
			pars[5].Value=sms_outbox.Reqdeliveryreport;
			pars[6].Value=sms_outbox.Msgfmt;
			pars[7].Value=sms_outbox.Sendmethod;
			pars[8].Value=sms_outbox.Requesttime;
			pars[9].Value=sms_outbox.Applicationid;
	
			return DBHelper.ExecuteNonQuery(Update_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region Delete
		public static int Delete(Sms_outbox sms_outbox)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@id",SqlDbType.Int)
				};
			pars[0].Value=sms_outbox.Id;
	
			return DBHelper.ExecuteNonQuery(Delete_CommandText,CommandType.Text,pars);
		}
		#endregion
		
		#region FindAll
		public static IList<Sms_outbox> FindAll()
		{
			return CommonQuery(FindAll_CommandText,CommandType.Text,null);
		}
		#endregion
		
		#region FindById
		public static Sms_outbox FindById(Int32 id)
		{
			SqlParameter[] pars = new SqlParameter[]{
				new SqlParameter("@id",SqlDbType.Int)
			};	
			pars[0].Value = id;
			IList<Sms_outbox> list = CommonQuery(FindById_CommandText,CommandType.Text,pars);
			return list.Count > 0 ? list[0] : null;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
		
		#region CommonQuery
		private static IList<Sms_outbox> CommonQuery(string commandText, CommandType cmdType, SqlParameter[] pars)
		{
			IList<Sms_outbox> list = new List<Sms_outbox>();
			Sms_outbox sms_outbox = null;
			
			using (SqlDataReader reader = DBHelper.ExecuteQuery(commandText,cmdType,pars))
           	{
				while(reader.Read())
				{
					sms_outbox = new Sms_outbox();
					sms_outbox.Id = Convert.ToInt32(reader["id"]);
					sms_outbox.Sismsid = Convert.ToString(reader["sismsid"]);
					sms_outbox.Extcode = Convert.ToString(reader["extcode"]);
					sms_outbox.Destaddr = Convert.ToString(reader["destaddr"]);
					sms_outbox.Messagecontent = Convert.ToString(reader["messagecontent"]);
					sms_outbox.Reqdeliveryreport = Convert.ToInt32(reader["reqdeliveryreport"]);
					sms_outbox.Msgfmt = Convert.ToInt32(reader["msgfmt"]);
					sms_outbox.Sendmethod = Convert.ToInt32(reader["sendmethod"]);
					sms_outbox.Requesttime = Convert.ToDateTime(reader["requesttime"]);
					sms_outbox.Applicationid = Convert.ToString(reader["applicationid"]);
					
					list.Add(sms_outbox);
				}
            }
            return list;
		}
		#endregion
		
		#region ??
		
		#endregion
		
		#region ??
		
		#endregion
	}
}



